package com.imau.controller;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet(name = "ResponseServlet2", value = "/ResponseServlet2")
public class ResponseServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        System.out.println("aaaaaa");
        //字节流
        ServletOutputStream outputStream = response.getOutputStream();
        //输出图片
        //1. 加载图片

        FileInputStream fis = new FileInputStream("E:\\aaa.jpg");

        byte buff[]= new byte[1024];

        int res=0;

        //最后读取的时候一般 -1 正数代表读取了多个字节数据
        while((res = fis.read(buff))!=-1 )
        {
            //2. 输出到客户端
            outputStream.write(buff,0,res);
        }




    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doGet(request,response);
    }
}
